package com.mq.dpca.util;

import java.io.*;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Date;
import java.util.Enumeration;

public class Ping {
	public static void main(String args[]) {
		// String ip = "localhost";
		// String line = null;
		// String command = "ping -t " + ip;
		//
		// try {
		// System.out.println(ip);
		// Process pro = Runtime.getRuntime().exec(command);
		// BufferedReader buf = new BufferedReader(new InputStreamReader(
		// pro.getInputStream()));
		// while ((line = buf.readLine()) != null)
		// System.out.print(line + "\r\n");
		// } catch (Exception ex) {
		// System.out.println(ex.getMessage());
		// }
		Ping ping = new Ping();
		System.out.println(new Date().getTime());
		System.out.println(ping.isAddressAvailable("10.26.211.39"));
		System.out.println(new Date().getTime());
	}

	public static boolean isAddressAvailable(String ip) {
		boolean resut = false;
		try {
			InetAddress address = InetAddress.getByName(ip);
			if (address.isReachable(5000)) {
				resut=true;
			}
		} catch (Exception e) {
			System.out.println("error occurs.");
			e.printStackTrace();
		}
		return resut;
	}
}